# Use Ubuntu:16.04 image as parent image
FROM ubuntu:16.04
# Modify apt to aliyun mirror
WORKDIR /
#RUN sed -i 's/archive.ubuntu/mirrors.aliyun/g' /etc/apt/sources.list
ADD sources.list /etc/apt/
# Install necessary library
RUN apt-get update && apt-get install -y build-essential wget cmake git pkg-config python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev && apt-get clean

# install ffmpeg3.2.14
WORKDIR /install_env
RUN wget https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/nasm-2.14.02.tar.gz && \
    wget http://www.ffmpeg.org/releases/ffmpeg-3.2.14.tar.bz2 && \
    wget https://download.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20191205-2245-stable.tar.bz2 &&\
    tar -xvf ffmpeg-3.2.14.tar.bz2 && tar -xvf nasm-2.14.02.tar.gz&& tar -xvf x264-snapshot-20191205-2245-stable.tar.bz2 &&\
    cd /install_env/nasm-2.14.02 && ./configure --enable-static --enable-shared --enable-pic && make -j4 && make install &&\
    cd /install_env/nasm-2.14.02 && ./configure --enable-static --enable-shared --enable-pic && make -j4 && make install &&\
    cd /install_env/x264-snapshot-20191205-2245-stable &&./configure --enable-shared  && make && make install &&\
    cd /install_env/ffmpeg-3.2.14 &&./configure --enable-static --enable-shared --enable-pic  --enable-libx264 --enable-gpl && make -j4 && make install &&\
    cd /install_env && rm -rf *
COPY 4.0.0 /install_env/4.0.0
RUN cd /install_env/4.0.0/build && cmake  -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local/opencv-4.0.0  -D BUILD_TIFF=ON -D WITH_FFMPEG=ON -D CUDA_GENERATION=Auto .. && make -j8 && make install && cd ..&& rm -rf build
RUN cd /install_env && wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz && tar -xvf libiconv-1.16.tar.gz && cd libiconv-1.16 && \
    ./configure && make install &&\
    cd /install_env && wget https://pocoproject.org/releases/poco-1.9.4/poco-1.9.4-all.tar.gz --no-check-certificat&& tar -xvf poco-1.9.4-all.tar.gz && cd poco-1.9.4-all &&\
    mkdir mybuild && cd mybuild && apt-get install -y openssl libssl-dev libmysqlclient-dev  && apt-get clean &&cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/poco && make install &&\
    cd /install_env && rm -rf * 
ENV LD_LIBRARY_PATH /usr/local/poco/lib:/usr/local/opencv-4.0.0/lib:/usr/local/lib:$LD_LIBRARY_PATH
RUN git clone https://gitee.com/xuxudong/irbgrfusionstreamer.git && cd irbgrfusionstreamer &&\
    cmake . -DCMAKE_INSTALL_PREFIX=/usr/local  &&\
    make install && cd /install_env && rm -rf *
WORKDIR /app
CMD ["mainapprpc"]
#CMD [ "/bin/bash" ]